﻿using System;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.Linq;
using Tisbi.LawFirm.DAL.Models;

namespace Tisbi.LawFirm.UI.ViewModel
{
    public class AppealsCRUDViewModel : BaseCRUDItemViewModel<Appeals>
    {
        public AppealsCRUDViewModel(Appeals model) : base(model)
        {
        }

        public DateTime? SelectedHearingDate
        {
            get { return Model.HearingDate; }
            set
            {
                Model.HearingDate = value;
                RaisePropertyChanged(() => SelectedHearingDate);
            }
        }


        public AppealsType SelectedAppealsType
        {
            get { return Model.AppealsType; }
            set
            {
                Model.AppealsType = value;
                RaisePropertyChanged(() => SelectedAppealsType);
            }
        }

        public IEnumerable<AppealsType> AppealsTypes { get; set; }

        private ObservableCollection<Court> _locations;
        public ObservableCollection<Court> Locations
        {
            get { return _locations; }
            set
            {
                _locations = value;
                if (Model.Location != null)
                {
                    SelectedLocation = Locations.First(x => x.Id == Model.Location.Id);
                }
                RaisePropertyChanged(() => Locations);
            }
        }

        public Court SelectedLocation
        {
            get { return Model.Location; }
            set
            {
                Model.Location = value;
                RaisePropertyChanged(() => SelectedLocation);
            }
        }

        public string Title
        {
            get { return Model.Title; }
            set
            {
                Model.Title = value;
                RaisePropertyChanged(() => Title);
            }
        }

        public override string Error
        {
            get
            {
                return this["Title"];
            }
        }

        public override string this[string columnName]
        {
            get
            {
                string result = string.Empty;
                switch (columnName)
                {
                    case "Title":
                        if (string.IsNullOrWhiteSpace(Model.Title)) result = "Поле 'Название аппеляции' обязательное";
                        break;
                }
                return result;
            }
        }
    }
}
